Public Sub SplitBatchByClass(ByRef pXRootFolder As CASCADELib.CscXFolder) 'splits a batch into multiple batches based document classification 'pXRootFolder - the root folder (batch level) object where document routing needs to be set 'counter for new batches created Dim intBatchCount As Integer 'xdoc info object Dim xDocInfo As CscXDocLib.CscXDocInfo 'general counter Dim i As Integer 'set counter of new batches intBatchCount = 0 'loop all documents in the batch For i = 0 To pXRootFolder.GetTotalDocumentCount - 1 'get the xdocinfo for this document Set xDocInfo = pXRootFolder.GetDocInfoByGlobalIndex(i) 'if we haven't created a batch for this class yet, create it now If pXRootFolder.XValues.ItemExists("KTM_DOCUMENTROUTING_BATCHNAME_" & "SPLITBATCH" & xDocInfo.ExtractionClass)=False Then 'increment the count of batches intBatchCount=intBatchCount+1 'create a new batch flag at the XRootFolder level - this creates the new batch pXRootFolder.XValues.Set("KTM_DOCUMENTROUTING_BATCHNAME_" & "SPLITBATCH" & xDocInfo.ExtractionClass, pXRootFolder.XValues("AC_BATCH_NAME") & " " & CStr(intBatchCount)) End If 'mark this document as belonging to the relevant batch xDocInfo.XValues.Set("KTM_DOCUMENTROUTING", "SPLITBATCH" & xDocInfo.ExtractionClass) Next End Sub